# Maintainer: Alexey Pavlov <alexpux@gmail.com>

pkgname=('texinfo' 'info' 'texinfo-tex')
pkgver=6.7
pkgrel=3
pkgdesc="Utilities to work with and produce manuals, ASCII text, and on-line documentation from a single source file"
arch=('i686' 'x86_64')
url="https://www.gnu.org/software/texinfo/"
license=('GPL3')
makedepends=('ncurses-devel' 'gettext-devel' 'findutils' 'gzip' 'perl-devel')
source=(https://ftp.gnu.org/pub/gnu/${pkgname}/${pkgname}-${pkgver}.tar.xz{,.sig}
        texinfo-install.hook
        texinfo-remove.hook
        0000-documentencoding-is-not-file-specific.patch
        0001-texinfo-6.7-msys2.patch
        0002-manifest.all.patch
        0004-no-w32-stuff.msys2.patch
        0005-fix-makeinfo-exeext.msys2.patch
        0006-match-msys-gettext-version.patch)
sha256sums=('988403c1542d15ad044600b909997ba3079b10e03224c61188117f3676b02caa'
            'SKIP'
            'c62f9c072d0c91531a557585c7b6cd6ef92e547de72da918ef3fb399182883fa'
            'e910ebddab9d3c82300caf1e3449960eb5cae756f6c708efd6ad51fc508feb7b'
            'd16bd1fe877ccf9f96827ff4811afcd986f575d86fd839adf62a67d64555ffc0'
            '18c9b8118c1c0774298a16efd02d2e9c72523c0bc234ad33f21d141d14bd81e0'
            'db2c67546da5f11dc8e374dbf70269227a0df15045dc3456f7a9e74c353083d5'
            'ccf696f2777ebd2c85c4cb311a4735957ffa40952ecbe50c7031b9f05dc6cdee'
            'e5b18f11d9a5d99f96f9228266e6204cfb2e076e2d9c336db0eceb72e2252873'
            'f30442c35aa9e56740f718f80958450c313beb8ea896864e13046de1c574e3f3')
validpgpkeys=('EAF669B31E31E1DECBD11513DDBC579DAB37FBA9') # Gavin Smith

prepare() {
  cd ${srcdir}/${pkgname}-${pkgver}
  #patch -p1 -i ${srcdir}/0000-documentencoding-is-not-file-specific.patch
  patch -p1 -i ${srcdir}/0001-texinfo-6.7-msys2.patch
  patch -p1 -i ${srcdir}/0002-manifest.all.patch
  patch -p1 -i ${srcdir}/0004-no-w32-stuff.msys2.patch
  patch -p1 -i ${srcdir}/0005-fix-makeinfo-exeext.msys2.patch
  patch -p1 -i ${srcdir}/0006-match-msys-gettext-version.patch

  autoreconf -fiv
  pushd tp/Texinfo/XS
    autoreconf -fiv
  popd
}

build() {
  cd ${srcdir}/${pkgname}-${pkgver}
  ./configure \
    --build=${CHOST} \
    --prefix=/usr \
    --without-libiconv-prefix \
    --without-libintl-prefix \
    --enable-perl-xs

  make
  make DESTDIR=${srcdir}/dest install
}

check() {
  cd ${srcdir}/${pkgname}-${pkgver}
  make check
}

package_texinfo() {
  depends=('info' 'perl' 'sh')
  groups=('base-devel')

  mkdir -p ${pkgdir}/usr/{bin,lib}
  mkdir -p ${pkgdir}/usr/share/info
  mkdir -p ${pkgdir}/usr/share/man/man{1,5}
  for ff in makeinfo pod2texi texi2any; do
    cp -f ${srcdir}/dest/usr/bin/${ff} ${pkgdir}/usr/bin/${ff}
    cp -f ${srcdir}/dest/usr/share/man/man1/${ff}.1 ${pkgdir}/usr/share/man/man1/${ff}.1
  done
  cp -rf ${srcdir}/dest/usr/lib/texinfo ${pkgdir}/usr/lib/
  cp -rf ${srcdir}/dest/usr/share/locale ${pkgdir}/usr/share/
  cp -rf ${srcdir}/dest/usr/share/texinfo ${pkgdir}/usr/share/
  cp -f ${srcdir}/dest/usr/share/man/man5/texinfo.5 ${pkgdir}/usr/share/man/man5/
  cp -f ${srcdir}/dest/usr/share/info/texinfo.info{,-1,-2,-3} ${pkgdir}/usr/share/info/
}

package_info() {
  depends=('gzip' 'libcrypt' 'libintl' 'ncurses')

  mkdir -p ${pkgdir}/usr/{bin,share}
  mkdir -p ${pkgdir}/usr/share/info
  mkdir -p ${pkgdir}/usr/share/man/man{1,5}
  for ff in info install-info; do
    cp -f ${srcdir}/dest/usr/bin/${ff}.exe ${pkgdir}/usr/bin/${ff}.exe
    cp -f ${srcdir}/dest/usr/share/man/man1/${ff}.1 ${pkgdir}/usr/share/man/man1/${ff}.1
  done
  cp -f ${srcdir}/dest/usr/share/man/man5/info.5 ${pkgdir}/usr/share/man/man5/info.5
  cp -f ${srcdir}/dest/usr/share/info/info-stnd.info ${pkgdir}/usr/share/info/info-stnd.info

  install -dm755 "${pkgdir}"/usr/share/libalpm/hooks/
  install -m644 texinfo-{install,remove}.hook "${pkgdir}"/usr/share/libalpm/hooks/
}

package_texinfo-tex() {
  depends=('gawk' 'perl' 'sh')
  groups=('base-devel')

  mkdir -p ${pkgdir}/usr/{bin,share}
  mkdir -p ${pkgdir}/usr/share/man/man1
  for ff in texindex texi2dvi texi2pdf pdftexi2dvi; do
    cp -f ${srcdir}/dest/usr/bin/${ff} ${pkgdir}/usr/bin/${ff}
    cp -f ${srcdir}/dest/usr/share/man/man1/${ff%.*}.1 ${pkgdir}/usr/share/man/man1/${ff%.*}.1
  done
}
